import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: HomePage());
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final List<String> _list = [];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Flutter App"),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // 改变数据必须加上setState
          setState(() {
            _list.add("我是一个新增列表");
          });
        },
        child: Icon(Icons.add),
      ),
      body: ListView(
        children: _list.map((value) {
          return ListTile(
            title: Text(value),
          );
        }).toList(),
      ),
    );
  }
}
